//
//  ViewController.m
//  二维码扫描和生成
//
//  Created by Yanyongliang on 16/10/12.
//  Copyright © 2016年 💫闫永亮💫. All rights reserved.
//

#import "ViewController.h"
#import <QRCodeGenerator.h>
#import <ZBarReaderViewController.h>
@interface ViewController ()<ZBarReaderDelegate>
@property (weak, nonatomic) IBOutlet UITextField *TFshibie;

@property (weak, nonatomic) IBOutlet UIImageView *SCimage;
@end

@implementation ViewController
//生成
- (IBAction)shengcheng:(id)sender {
     self.SCimage.image=[QRCodeGenerator qrImageForString:self.TFshibie.text imageSize:250];
    UIImageWriteToSavedPhotosAlbum(self.SCimage.image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);
    
    }
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
{
    if (error) {
        NSLog(@"存不上");
        NSLog(@"HAHHA");
    }else
    {
        NSLog(@"存上了");
    }
    
}
//识别
- (IBAction)shibie:(id)sender {
    ZBarReaderViewController *reader=[[ZBarReaderViewController alloc]init];
    reader.readerDelegate=self;
    [self presentViewController:reader animated:YES completion:nil];
    
    
}
#pragma mark 识别代理
//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo NS_DEPRECATED_IOS(2_0, 3_0);
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info;
{
    NSLog(@"%@",info);
    ZBarSymbolSet *set=[info objectForKey:ZBarReaderControllerResults];
    id<NSFastEnumeration> fastEnum;
    for (fastEnum in set) {
        NSLog(@"%@",set);
        ZBarSymbol *sybol=(ZBarSymbol *)fastEnum;
        self.TFshibie.text=sybol.data;
        
    }

}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
{
    [picker dismissViewControllerAnimated:YES completion:nil];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
